<%@page import="java.util.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="css/backstyle.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="js/jquery.js"></script>

    <!-- 1、引入-->
    <script type="text/javascript" src="js/productType.js"></script>


    <script type="text/javascript">
        $(function () {

            // 1.获取pid
            var pid = "${productType.pid}";

            // 1.初始化父类別,初始化完成后，自动帮我选中
            initParentType(pid); // 使用的异步(这个方法执行完了未必父类別初始化了) 你帮我去楼下买包烟

            // 2.我就已经拿到烟了

            // 2.选中当前修改的类别的pid

            // $("#pid").val(pid);


            $("#productTypeForm").submit(function () {
                // 1.获取表单数据
                var formArray = $("#productTypeForm").serializeArray();

                // 2.封装
                var param = new Object();
                for (var i = 0; i < formArray.length; i++) {
                    var name = formArray[i].name; // 获取表单属性
                    var value = formArray[i].value; // 获取表单值
                    param[name] = value;
                }

                // 3.发送请求
                $.ajax({
                    url: "ProductTypeController/updateProductType",
                    type: "POST",
                    dataType: "JSON", // 服务端返回的数据格式
                    contentType: "application/json", // 前端传递的数据格式
                    data: JSON.stringify(param), // 把JS地址转成JSON字符串
                    success: function (data) {
                        if (data.code == 200) {
                            location.href = "ProductTypeController/productTypePage";
                        }
                    }
                });
                return false; // 返回false不让表单自己提交，需要使用异步提交
            });

        })
    </script>
</head>

<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">首页</a></li>
        <li><a href="#">表单</a></li>
    </ul>
</div>

<div class="formbody">

    <div class="formtitle"><span>修改商品类别信息</span></div>
    <form method="post" id="productTypeForm">
        <ul class="forminfo">
            <input type="hidden" name="id" value="${productType.id}"></input>
            <li><label>商品类别名称</label><input name="name" value="${productType.name}" type="text" class="dfinput"/><i>标题不能超过30个字符</i>
            </li>

            <li>
                <label>父类别</label>
                <select name="pid" id="pid">
                    <option value="-1">无</option>
                </select>
            </li>
            <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认保存"/></li>
        </ul>
    </form>
</div>


<div style="display:none">
    <script src='http://v7.cnzz.com/stat.php?id=155540&web_id=155540' language='JavaScript' charset='gb2312'></script>
</div>
</body>
</html>

